package com.baseframe.sys.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baseframe.sys.entity.FrameOu;
import com.baseframe.sys.service.IFrameOuService;
import com.baseframe.sys.service.dao.FrameOuRepository;

/**
 * @author mzl
 */
@Service("frameOuService")
public class FrameOuServiceImpl implements IFrameOuService {


    @Autowired
    private FrameOuRepository sysouRepository;

    @Override
    public List<FrameOu> selectList() {
        return sysouRepository.findAll();
    }

    @Override
    public FrameOu selectById(String ouId) {
        return sysouRepository.findOne(ouId);
    }

    @Override
    public List<FrameOu> queryListParentId(String parentId, List<String> ouIdList) {
        List<FrameOu> ouList = queryListParentId(parentId);
        if (ouIdList == null) {
            return ouList;
        }

        List<FrameOu> userouList = new ArrayList<>();
        for (FrameOu ou : ouList) {
            if (ouIdList.contains(ou.getOuguid())) {
                userouList.add(ou);
            }
        }
        return userouList;
    }

    @Override
    public List<FrameOu> queryListParentId(String parentId) {
        return sysouRepository.findByParentouguid(parentId);
    }



    @Override
    public void delete(String ouId) {
        //删除菜单
        sysouRepository.delete(ouId);
    }

    @Override
    public void insert(FrameOu FrameOu) {
        sysouRepository.save(FrameOu);
    }

    @Override
    public void update(FrameOu FrameOu) {
        sysouRepository.save(FrameOu);
    }

    /**
     * 递归
     *//*
    private List<FrameOu> getouTreeList(List<FrameOu> ouList, List<String> ouIdList) {
        List<FrameOu> subouList = new ArrayList<>();

        for (FrameOu entity : ouList) {
            //目录
            if (entity.getModuletype() == Constant.ouType.CATALOG.getValue()) {
                entity.setList(getouTreeList(queryListParentId(entity.getModuleguid(), ouIdList), ouIdList));
            }
            subouList.add(entity);
        }

        return subouList;
    }*/

	
}
